<?php
include("include/config.inc.php");
$joinResult = array();
$i=0;
$joinOrderMasterOrderedItems = " SELECT waiter.waiterName, waiter.waiterId, ordermaster.tablePart, ordermaster.tableId, 
                                        sum( ordereditems.quantity * item.itemPrice ) AS totalamount, SUM( quantity ) AS totalItem, 
                                        ordermaster.startTime, ordermaster.orderId ,MAX( ordereditems.orderTime ) AS lastordertime
                                   FROM ordermaster
                                   JOIN ordereditems ON ordermaster.orderId = ordereditems.orderId
                                   JOIN item ON item.itemId = ordereditems.itemId
                                   JOIN waiter ON waiter.waiterId = ordermaster.waiterId
                                  WHERE ordermaster.orderstatus = 'L'
                                  GROUP BY ordermaster.tableId 
                                  ORDER BY  ordermaster.startTime DESC";
$joinOrderMasterOrderedItemsRes = mysql_query($joinOrderMasterOrderedItems);
while($joinOrderMasterOrderedItemsRow = mysql_fetch_array($joinOrderMasterOrderedItemsRes))
{
	 $joinResult[$i]['waiterName']    = $joinOrderMasterOrderedItemsRow['waiterName'];
	 $joinResult[$i]['waiterId']      = $joinOrderMasterOrderedItemsRow['waiterId'];
	 $joinResult[$i]['tableId']       = $joinOrderMasterOrderedItemsRow['tableId'];
	 $joinResult[$i]['tablePart']     = $joinOrderMasterOrderedItemsRow['tablePart'];
	 $joinResult[$i]['totalamount']   = $joinOrderMasterOrderedItemsRow['totalamount'];
	 $joinResult[$i]['totalItem']     = $joinOrderMasterOrderedItemsRow['totalItem'];
	 $joinResult[$i]['startTime']     = $joinOrderMasterOrderedItemsRow['startTime'];
	 $joinResult[$i]['lastordertime'] = $joinOrderMasterOrderedItemsRow['lastordertime'];
	 $joinResult[$i]['tablePart']     = $joinOrderMasterOrderedItemsRow['tablePart'];
	 $joinResult[$i]['orderId']       = $joinOrderMasterOrderedItemsRow['orderId'];
	 $i++;
}
include("./bottom.php");
$smarty->assign('joinResult',$joinResult);
$smarty->display('currentTables1.tpl');
?>